package com.edu.nju.nationalflag;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.GridView;
import android.widget.SimpleAdapter;

public class LocalFlagFragment extends Fragment{
	private GridView grid;
	private int[] imageIds;
	private String[] flagNames;
	
	
	public LocalFlagFragment() {
		super();
	}
	
	

	@Override
	public void onStart() {
		super.onStart();
		
		imageIds = new int[]{
				R.drawable.japan,R.drawable.mongolia,R.drawable.north_korea,R.drawable.south_korea,
				R.drawable.the_peoples_republic_of_china,R.drawable.the_republic_of_china,R.drawable.north_pole
		};
		flagNames = getResources().getStringArray(R.array.flagnames);
		
		List<Map<String,Object>> listItems = new ArrayList<Map<String,Object>>();
		for(int j=0;j<imageIds.length;j++){
			Map<String,Object> listItem = new HashMap<String,Object>();
			listItem.put("image", imageIds[j]);
			listItem.put("flagName", flagNames[j]);
			listItems.add(listItem);
		}
		
		SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity(), listItems, R.layout.gridview_cell, 
				new String[]{"image","flagName"}, new int[]{R.id.imageView_cell,R.id.textView_cell});
		grid = (GridView)getActivity().findViewById(R.id.colorResultGrid);
		grid.setAdapter(simpleAdapter);
	}



	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.localflag_viewpager, container, false);
		return view;
		
		/*grid.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onNothingSelected(AdapterView<?> arg0) {
				// TODO Auto-generated method stub
				
			}
		});
		
		grid.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1,
					int arg2, long arg3) {
				// TODO Auto-generated method stub
				
			}
		});*/
		
	}
	
}
